TEMPORARY TABLES



MySQL - Temporary Tables


In MySQL, a temporary table is a special type of table that allows you to store a temporary result set, which you can reuse several times in a single session. A temporary table is very handy when it is impossible or expensive to query data that requires a single SELECT statement with the JOIN clauses.


A MySQL temporary table has the following specialized features:


  • A temporary table is created by using CREATE TEMPORARY TABLE statement. Notice that the keyword TEMPORARY is added between the CREATE and TABLE keywords.

  • MySQL removes the temporary table automatically when the session ends or the connection is terminated. Of course, you can use the DROP TABLE statement to remove a temporary table explicitly when you are no longer use it.

  • A temporary table is only available and accessible to the client that creates it. Different clients can create temporary tables with the same name without causing errors because only the client that creates the temporary table can see it. However, in the same session, two temporary tables cannot share the same name.

  • A temporary table can have the same name as a normal table in a database. For example, if you create a temporary table named employees in the sample database, the existing employees table becomes inaccessible. Every query you issue against the employees table is now referring to the temporary table employees. When you drop the employees temporary table, the permanent employees table is available and accessible.


    SYNTAX :

    CREATE TEMPORARY TABLE table_name(
       column_1_definition,
       column_2_definition,
       ...,
       table_constraints
    );
    

    CREATE TEMPORARY TABLE :


    CREATE TEMPORARY TABLE credits(
        customerNumber INT PRIMARY KEY,
        creditLimit DEC(10,2)
    );
    
    
    

    Temporary table gets created.



    MySQL TRIGGERS

    MySQL - Triggers

    posted on 2019-11-29 21:44:07 - mysql Tutorials


    Grant_ Revoke Privilege

    MySQL - Grant_ Revoke Privilege

    posted on 2019-11-26 23:15:04 - mysql Tutorials


    MySQL Vs SQL

    MySQL Vs SQL

    posted on 2019-11-25 05:02:26 - mysql Tutorials


    Prompt Examples

    ChatGPT Prompt Examples

    posted on 2023-06-21 22:37:19 - ChatGPT Tutorials


    Use Cases

    Chat GPT Key Use Cases

    posted on 2023-06-21 21:03:17 - ChatGPT Tutorials


    Prompt Frameworks

    Prompt Frameworks

    posted on 2023-06-21 19:33:06 - ChatGPT Tutorials